<?php
/**
 * Template Name: KnowledgeCenter - Section
 * Description: The section page for each KC section
 *
 * @package ManterRealty
 * 
 */

get_header(); ?>
		
        <div class="kc_wrap kc_section">
        	<?php if ( have_posts() ) : ?>
            	<?php while ( have_posts() ) : the_post(); ?>
					<div class="cols cols_2cols kc_cols kc_cols_2cols clearfix">
                   
                    	<div class="col col_1">
                        	<div class="col_pad">
                            
                            	<div class="sec_nav_wrap">
									<div class="sec_nav_pad">
										<ul class="sec_nav">
										<?php
											// declare custom fields before entering deeper loops
											$vals = get_post_custom_values('intro_thumbnail',$page->ID);
											$intro_thumbnail = wp_get_attachment_image_src($vals[0], 'full');
											//
											
											$parent = 34; // Knowledge Center
											$args=array(
											  'child_of' => $parent
											);
											$pages1 = get_pages($args);  
											if ($pages1) {
												$pageids = array();
												foreach ($pages1 as $page) {
													$pageids[]= $page->ID;
												}
												
												$args=array(
													'title_li' => '',
													'include' =>  $parent . ',' . implode(",", $pageids)
												);
												wp_list_pages($args);
											}
										?> 
										</ul>
									</div>
                                </div>
                                
                                <div class="callout_wrap">
                                	<div class="callout_pad">
                                    	
                                    </div>
                                </div>
                                
                            </div>
                        </div>
                    	
                        <div class="col col_2">
							
								<div class="kc_section_intro clearfix">
									<div class="kc_section_intro_image">
										<?php 	
											echo('<img class="" src="'.$intro_thumbnail[0].'" />');
										?>
									</div>
									<div class="kc_section_intro_content">
										<h1><?php the_title(); ?></h1>
										<?php 	
											the_content();
										?>
									</div>
								</div>
								
								<?php 
								$thisSection = $post->ID;
								$sectionChildren = get_pages('child_of='.$thisSection.'&parent='.$thisSection.'&sort_column=menu_order&sort_order=asc');
								
								
								foreach($sectionChildren as $subsection) {
									
									
									$pageLink = get_permalink($subsection->ID);
									$pageTitle = get_the_title($subsection->ID);
									
									$vals = get_post_custom_values('section_landing_icon',$subsection->ID);
									$subsectionIcon = wp_get_attachment_image_src($vals[0], 'full');
									
									$vals = get_post_custom_values('section_landing_teaser',$subsection->ID);
									$subsectionTeaser = $vals[0];
									
									echo('<div class="kc_section_item">');
										echo('<div class="item_icon"><a href="'.$pageLink.'"><img src="'.$subsectionIcon[0].'" /></a></div>');
										echo('<div class="item_content">');
											echo('<div class="item_title"><a href="'.$pageLink.'">'.$pageTitle.'</a></div>');
											echo('<div class="item_text">'.$subsectionTeaser.'</div>');
										echo('</div>');
									echo('</div>');
									
								}
                            ?>
                        </div>
						
                    </div>
				<?php endwhile; ?>
             <?php endif; ?>
        </div>

<?php get_footer(); ?>